package com.xinghen.common.base.exception;

import com.xinghen.common.base.enums.ErrorType;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @author xinghen
 * @ClassName: BusinessException
 * @Package: com.xinghen.common.core.exception
 * @Description 自定义业务异常类基类
 * @create 2018-04-11 17:10
 */
@Data
@Slf4j
public class BusinessException extends RuntimeException {

    /**
     * 错误码
     */
    private int code;

    public BusinessException() {
    }

    public BusinessException(Throwable cause) {
        super(cause);
    }

    public BusinessException(String message) {
        super(message);
    }

    public BusinessException(int code, String message) {
        super(message);
        this.code = code;
    }

    public BusinessException(String message, Throwable cause) {
        super(message, cause);
    }

    public BusinessException(int code, String msgFormat, Object... args) {
        super(String.format(msgFormat, args));
        this.code = code;
    }

    public BusinessException(ErrorType errorType, Object... args) {
        super(String.format(errorType.getMsg(), args));
        this.code = errorType.getCode();
    }
}
